package io.gitee.yth.design.pattern.test.core.pattern.structural.composite.code;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yth
 * @since 2023-04-26-21:21
 */
public class University extends Organization {

    private final List<College> components = new ArrayList<>();

    public University(String name, String description) {
        this.name = name;
        this.description = description;
    }

    @Override
    public void printAll() {
        System.out.println("----------University----------");
        System.out.println(name);
        System.out.println(description);
        components.forEach(Organization::printAll);
        System.out.println("----------End----------");

    }

    @Override
    protected void add(Organization organization) {
        if (!(organization instanceof College)) {
            throw new IllegalArgumentException();
        }
        components.add((College) organization);
    }

    @Override
    protected void remove(Organization organization) {
        if (!(organization instanceof College)) {
            throw new IllegalArgumentException();
        }
        components.remove(organization);
    }

    @Override
    protected College getChild(int i) {
        return components.get(i);
    }
}
